class WordMap:
    def __init__(self):

        # 右上角小地图坐标
        self.mini_loc = (900, 90)

        self.map_data = {
            "name": "世界地图",
            "loc": (80, 490),
            "parts": [
                {
                    "name": "阿拉德大陆",
                    "loc": (80, 160),
                    "parts": [
                        {
                            "name": "贝尔玛尔公国北部",
                            "loc": (450, 200),
                            "parts": [
                                {
                                    "name": "洛兰",
                                    "loc": (780, 320),
                                    "icon": "images/map/luolan.bmp",
                                    "target": [(300, 360), (190, 260)]  # 封锁的试验场、关卡数
                                }
                            ]
                        },
                        {
                            "name": "贝尔玛尔公国南部",
                            "loc": (390, 400),
                            "parts": [
                                {
                                    "name": "诺斯玛尔",
                                    "loc": (290, 240),
                                    "icon": "images/map/nosemaer.bmp",
                                    "target": [(740, 320), (180, 410)]  # 迷乱之村、关卡数
                                }
                            ]
                        }
                    ]
                },
                {
                    "name": "天界",
                    "loc": (80, 240),
                    "parts": [
                        {
                            "name": "皇都",
                            "loc": (610, 260),
                            "parts": [
                                {
                                    "name": "安特贝鲁峡谷",
                                    "loc": (360, 150)
                                }
                            ]
                        }
                    ]
                }
            ]
        }

    def get_path(self, map_name):
        path = self.__depth_first_search(self.map_data, map_name)
        # 最后一个节点
        node = path[-1]
        return path, node.get("icon"), node.get("target")

    def __depth_first_search(self, map, find_name):
        # print(map)

        path = [self.__deal_data(map)]

        if map.get("name") == find_name:
            return path

        parts = map.get("parts")
        if parts is not None and len(parts) > 0:
            for child in parts:
                result = self.__depth_first_search(child, find_name)
                if result:
                    path.extend(result)
                    return path
        return None

    def __deal_data(self, data):
        if "target" in data:
            return {
                "name": data.get("name"),
                "loc": data.get("loc"),
                "icon": data.get("icon"),
                "target": data.get("target")
            }
        else:
            return {
                "name": data.get("name"),
                "loc": data.get("loc"),
            }


if __name__ == "__main__":
    word_map = WordMap()
    path, icon, target = word_map.get_path("洛兰")
    print(path)
    print(icon)
    print(target)
